﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace NF_Web
{
    public partial class FrmBase : Form
    {
        public FrmBase()
        {
            InitializeComponent();
            this.pnlClose.MouseEnter += pnlClose_MouseEnter;
            this.pnlClose.MouseLeave += pnlClose_MouseLeave;
            this.pnlClose.MouseClick += pnlClose_MouseClick;
            this.pnlTop.MouseDown +=pnlTop_MouseDown;
        }



        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        
        /// <summary>
        /// 重新绘制
        /// </summary>
        private void FrmBase_Paint(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(Color.Gray);
            Graphics gs = e.Graphics;
            gs.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1);
        }

        void pnlClose_MouseEnter(object sender, EventArgs e)
        {
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.icon_close_hover;
            }
        }


        void pnlClose_MouseLeave(object sender, EventArgs e)
        {
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.Close;
            }
        }

        void pnlClose_MouseClick(object sender, MouseEventArgs e)
        {
            this.Close();
        }

        void pnlTop_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }

    }
}
